#ifndef PUSHWORK_H
#define PUSHWORK_H

#include<string>
#include"audiocapturer.h"
#include"videocapturer.h"
#include"aacencoder.h"
#include"h264encoder.h"
#include"rtsppusher.h"

extern "C"{
#include"libavcodec/avcodec.h"
#include"libswresample/swresample.h"
#include"libavutil/opt.h"
#include"libavutil/audio_fifo.h"
}


///
/// \brief The PushWork class
/// 推流类
///
class PushWork
{
public:
    PushWork();
    ~PushWork();
    RET_CODE init(const Properties properties);
    RET_CODE deInit();
private:
    void pcmCallback(uint8_t* pcm, int32_t size);
    void yuvCallback(uint8_t* yuv, int32_t size);
    // 这里的字段参数给的都是默认数据，其实无效，都会被传入的 properties 给覆盖
private:
    // 音频
    AudioCapturer* _audio_capturer = NULL;
    // 音频测试
    int _audio_test = 0;
    std::string _input_pcm_name;
    uint8_t* _fltp_buf = NULL;
    int _fltp_buf_size = 0;
    // 麦克风采样
    int _mic_sample_rate = 48000;
    int _mic_sample_format = AV_SAMPLE_FMT_S16;
    int _mic_channels = 2;
    // 音频编码器
    AACEncoder* _audio_encoder = NULL;
    int _audio_sample_rate = AV_SAMPLE_FMT_S16;
    int _audio_bit_rate = 128 * 1024;
    int _audio_channels = 2;
    int _audio_sample_fmt;//具体由编码器决定
    int _audio_channel_layout;//由audio_channles决定
    // 音频帧
    AVFrame *_audio_frame = NULL;

    // 视频
    VideoCapturer* _video_capturer = NULL;
    // 视频测试
    int _video_test = 0;
    std::string _input_yuv_name;
    // 桌面录制
    int _desktop_x;
    int _desktop_y;
    int _desktop_width;
    int _desktop_height;
    int _desktop_format;
    int _desktop_fps;
    // 视频编码器
    H264Encoder *_video_encoder = NULL;
    int _video_width = 1920;
    int _video_height = 1080;
    int _video_fps;
    int _video_gop;
    int _video_bit_rate;
    int _video_b_frames;

    // 测试dump文件
    FILE *_pcm_s16le_fp = NULL;
    FILE *_aac_fp = NULL;
    FILE *_yuv_fp = NULL;
    FILE *_h264_fp = NULL;

    // rtsp
    std::string _rtsp_url;
    std::string _rtsp_transport;
    RtspPusher *_rtsp_pusher = NULL;
    int _rtsp_timeout = 5000;
};

#endif // PUSHWORK_H
